﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Clinica_Frba.AbmdeProfesional
{
    public partial class elegir: Form
    {
        public elegir()
        {
            InitializeComponent();

        }

        private void elegir_Load(object sender, EventArgs e)
        {
            string comando;
            SqlConnection myConnection = new SqlConnection(publico.ConnectionString);
            myConnection.Open();
            comando = "SELECT * FROM DUNDER_MIFFLIN.PROFESIONAL";
            SqlDataAdapter da = new SqlDataAdapter(comando, myConnection);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            comboBox1.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int ide;
            SqlConnection myConnection = new SqlConnection(publico.ConnectionString);
            myConnection.Open();
            if (dataGridView1.SelectedRows.Count>1) {return;}
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                ide = Convert.ToInt32(row.Cells[0].Value);
                new Modificacion(ide).Show();
                
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string comando;
            SqlConnection myConnection = new SqlConnection(publico.ConnectionString);
            myConnection.Open();
            comando = "SELECT * FROM DUNDER_MIFFLIN.PROFESIONAL";
            if (comboBox1.Text == "Ambos") { comando = comando + " WHERE ESTADO LIKE '%'"; }
            if (comboBox1.Text == "Habilitado") { comando = comando + " WHERE ESTADO = 'H'"; }
            if (comboBox1.Text == "Inhabilitado") { comando = comando + " WHERE ESTADO = 'I'"; }
            if (textBox1.Text != "") { comando = comando + " AND Nombre like '%"+textBox1.Text+"%'"; }
            if (textBox2.Text != "") { comando = comando + " AND Apellido like '%" + textBox2.Text + "%'"; }
            if (textBox3.Text != "") { comando = comando + " AND NRO_DOC= " + textBox3.Text; }
            if (textBox4.Text != "") { comando = comando + " AND CONVERT(datetime,FECHA_NACIMIENTO,103)=CONVERT(datetime,'" + textBox4.Text+"',103)"; }

            SqlDataAdapter da = new SqlDataAdapter(comando, myConnection);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            textBox4.Text = dateTimePicker1.Value.ToString("dd/MM/yyyy");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
